package com.yodawnla.roboAttack;

import org.anddev.andengine.entity.IEntity;
import org.anddev.andengine.entity.modifier.AlphaModifier;
import org.anddev.andengine.entity.modifier.IEntityModifier.IEntityModifierListener;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.util.modifier.IModifier;

import com.yodawnla.lib.YoActivity;
import com.yodawnla.roboAttack.system.SE;
import com.yodawnla.roboAttack.system.Values;

public class Monster extends AnimatedSprite
{
	boolean mIsBeHit = false;
	boolean mIsDie = false; 
	int mHp = 3;
	
	public Monster(float pX, float pY, TiledTextureRegion pTiledTextureRegion)
	{
		super(pX, pY, pTiledTextureRegion);
	}
	
	public Monster(float pX, float pY,float width,float height, TiledTextureRegion pTiledTextureRegion)
	{
		super(pX, pY,width,height, pTiledTextureRegion);
	}
	
	public void reduceHp()
	{
		if(mHp > 0)
			mHp = mHp - 1;		
	}
	
	public void setHp(int hp)
	{
		mHp = hp;
	}
	
	public int getHp()
	{
		return mHp;
	}

	public void setIsbeHit(boolean isBeHit)
	{
		mIsBeHit = isBeHit;
		if(isBeHit)
		{
			YoActivity.getBaseActivity().playSound(SE.Attack);
		}
	}
	
	public boolean getIsBeHit()
	{
		return mIsBeHit;
	}
	
	public void die()
	{
		mIsDie = true;
		IEntityModifierListener listener = new IEntityModifierListener() 
		{
			
			@Override
			public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) 
			{
			  
			}
			
			@Override
			public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) 
			{ 
				Monster.this.setPosition(-1000, -1000);
			}
		};
		this.clearEntityModifiers();
		this.registerEntityModifier(new AlphaModifier(0.2f, 1, 0,listener)); 
	}
	
	public boolean getIsDie()
	{
		return mIsDie;
	}
 
	public void resetMonster()
	{
		clearEntityModifiers();
		setAlpha(1);
		setVisible(true);
		mIsBeHit = false;
		mIsDie = false;
		mHp = Values.ROBO_MAX_LIFE;
	}
}